﻿@using Scorpicore.MVC.Models;

@{
    ViewBag.Title = "Топ 10 градове";
}

<h2 class="legend-title">Топ 10 регистрирани градове</h2>

<div>
    @(Html.Kendo()
        .Grid<PlacesFrequencyViewModel>()
        .Name("top-ten-places")
        .Columns(columns =>
            {
                columns.Template(t => { }).ClientTemplate(
                    "#= renderNumber(data) #"
                ).Width(40);
                columns.Bound(model => model.Name).Width(300);
                columns.Bound(model => model.Count).Width(300);
            })
                    .Events(ev => ev.DataBound("resetRowNumber").DataBound("dataBound"))
            .DataSource(data =>
            {
                data.Ajax()
                    .Model(m => m.Id(b => b.Id))
                    .ServerOperation(true)
                    .Read("ReadPlaces", "TopTen");
            })
            .ClientDetailTemplateId("template-cities"))
</div>


<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }

    var rowNumber = 0;

    function resetRowNumber(e) {
        rowNumber = 0;
    }

    function renderNumber(data) {
        return ++rowNumber;
    }

</script>

<script id="template-cities" type="text/x-kendo-template">
    <strong>Следи</strong>
    @(Html.Kendo().Grid<TracksInTopTenBanknotesViewModel>()
                    .Name("grid_#=Id#")
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .PageSize(5)
                        .Read(read => read.Action("ReadTracksByName", "TopTen", new { Id = "#=Id#" }))
                    )
                    .Pageable()
                    .Sortable()
                    .ToClientTemplate())
</script>